$(function () {
    var getParams = getArgs();
    window.currentHotel = getParams.hotel;
    var originalHref = $('#doc-header a').attr('href');
    $('#doc-header a').attr('href', originalHref + '?hotel=' + window.currentHotel);
    var originalHref = $('.back-mian a').attr('href');
    $('.back-mian a').attr('href', originalHref + '?hotel=' + window.currentHotel);
    $('#doc-content').inputValidate({
        submit: {
            query: '#sendAgain'
        },
        inputs: [{
            query: '#requestMobile',
            regexp: window.commonRegexp.mobile.regexp,
            message: window.commonRegexp.mobile.message,
            emptyMessage: window.commonRegexp.mobile.emptyMessage
        }, {
            query: '#requestVerifiedCode',
            regexp: window.commonRegexp.imageCode.regexp,
            message: window.commonRegexp.imageCode.message,
            emptyMessage: window.commonRegexp.imageCode.emptyMessage
        }]
    });
    $('#sendAgain').on('successSubmit.amos.inputValidate', function (e) {
        var submitBtn = $(this);
        var params = {};
        params.mobile = $('#requestMobile').val();
        params.verify = $('#requestVerifiedCode').val();
        params.areaCode = $('.areaCodeValue').text().trim();
        toggleLoading(true);
        ajaxRequest('/Home/Public/smsLoginVcode', params, 'post', function (data) {
            toggleLoading(false);
            timeDisplay($('#sendAgain'), 60);
        }, function (error, obj, defaultErrorHandler) {
            toggleLoading(false);
            refreshVcode();
            defaultErrorHandler(error, obj);
        }, submitBtn);
    });

    $('#login-container').inputValidate({
        submit: {
            query: '#requestSubmit'
        },
        inputs: [{
            query: '#requestMobile',
            regexp: window.commonRegexp.mobile.regexp,
            message: window.commonRegexp.mobile.message,
            emptyMessage: window.commonRegexp.mobile.emptyMessage
        }, {
            query: '#requestMobileCode',
            regexp: window.commonRegexp.vcode.regexp,
            message: window.commonRegexp.vcode.message,
            emptyMessage: window.commonRegexp.vcode.emptyMessage
        }]
    });
    $('#requestSubmit').on('successSubmit.amos.inputValidate', function (e) {
        var submitBtn = $(this);
        var params = {};
        params.mobile = $('#requestMobile').val();
        params.vcode = $('#requestMobileCode').val();
        params.areaCode = $('.areaCodeValue').text().trim();
        toggleLoading(true);
        ajaxRequest('/Home/Public/smsLogin', params, 'post', function (data) {
            toggleLoading(false);
            window.location.href = '/Home/BookPage/index?hotel=' + window.currentHotel;
        }, function (error, obj, defaultErrorHandler) {
            toggleLoading(false);
            defaultErrorHandler(error, obj);
        }, submitBtn);
    });
    var getSubmitBtnTyle = function(){
        var mobile = $('#requestMobile').val();
        var vcode = $('#requestMobileCode').val();
        var requestVerifiedCode = $('#requestVerifiedCode').val();
        if(mobile && vcode && requestVerifiedCode){
            $('#requestSubmit').attr('disabled', false);          
        }else{
            $('#requestSubmit').attr('disabled', true);           
        }        
    };
    $('#doc-content').bind('input propertychange',function(){
        getSubmitBtnTyle();
    });
});
